var startPoint;
Page({
  data: {
    value: 0,
    val: 0,
    value2: 0,
    styles: [{
      line: '#dbdbdb',
      bginner: '#fbfbfb',
      bgoutside: '#dbdbdb',
      lineSelect: '#52b8f5',
      font: '#404040'
    }, {
      line: '#dbdbdb',
      bginner: '#fbfbfb',
      bgoutside: '#dbdbdb',
      lineSelect: '#52b8f5',
      font: '#404040'
    }],
    buttonTop: 400, //默认4cm
    // buttonTop: 502, //默认4cm
    // buttonTop: 800, //默认4cm

    buttonLeft: 0,
    windowHeight: '',
    windowWidth: '',

    min:0,
    max:100,
    step:1,
    single:8,

    //定义一个初始状态
    isStart:true,
    jiaozhi:5.40,
    startzhi:4.0001,

    jiaole:false,
    jiaobuttontop:0,

  },
  onLoad: function (options) {
    wx.getWindowInfo({
      success: res=> {
        this.setData({
          windowHeight: res.windowHeight,
          windowWidth: res.windowWidth
        })
      }
    })
    // console.log(this.data.windowHeight*0.1)

    let singleleing = wx.getStorageSync("singlele")
    let startValue = wx.getStorageSync("startzhi")
    let endtop = wx.getStorageSync("endtop")
    // console.log(singleleing,'单位角')
    // console.log(startValue,'初始值')
    if (singleleing==''){
      this.setData({
        startzhi:this.data.startzhi.toFixed(2),
      })
    }else{
      this.setData({
        startzhi:this.data.startzhi.toFixed(2),
        single:singleleing
      })
    }
    if (startValue!==''||endtop!==''){
      // console.log(11111)
      // console.log(endtop)
      this.setData({
        startzhi:startValue,
        buttonTop:endtop
      })
    }

  },

  buttonStart: function (e) {
    startPoint = e.touches[0]
  },


  //在这里做数据保存
  buttonMove: function (e) {
    var endPoint = e.touches[e.touches.length - 1]
    var translateX = endPoint.clientX - startPoint.clientX
    var translateY = endPoint.clientY - startPoint.clientY
    startPoint = endPoint
    var buttonTop = this.data.buttonTop + translateY
    // // console.log(buttonTop)
    // // console.log(buttonTop+'吱吱吱')  // 当前高度是在改变的
    if (buttonTop <= this.data.windowHeight*0.1) {
      buttonTop = this.data.windowHeight*0.1
    }
    if (buttonTop/2  >= this.data.windowHeight*1) {
      buttonTop = this.data.windowHeight*1*2 ;
    }
    if (this.data.isStart&&!this.data.jiaole){
      // console.log('开始')
      //最开始的时候
      let zhi = (buttonTop/(400/40)).toFixed(2)
      let endzhi = (zhi/10).toFixed(2)
      // // console.log(zhi,'起始未校验的值')
      this.setData({
        buttonTop: buttonTop, // 200/40
        startzhi:endzhi
      })
      wx.setStorageSync("endtop",buttonTop)
      wx.setStorageSync("startzhi",endzhi)
    }else if (!this.data.isStart&&!this.data.jiaole){
      // console.log('挪动进入1')
      let zhi = (buttonTop/(216/56)).toFixed(2)
      // console.log(zhi)
      let endzhi = (zhi/10).toFixed(2)
      // console.log(endzhi)
      let jiao = buttonTop/54
      // console.log(jiao)
      this.setData({
        buttonTop: buttonTop,
      })
      //存储挪动后的top
      wx.setStorageSync("endtop",buttonTop)
      wx.setStorageSync("startzhi",endzhi)
    }else if (this.data.jiaole){
      // console.log('挪动进入2')
      let zhi = ((buttonTop/2)/this.data.jiaobuttontop).toFixed(2)
      let endzhi = (zhi/10).toFixed(2)
      // console.log(buttonTop+'但其方法')
      // // console.log(((buttonTop/2)/this.data.jiaobuttontop).toFixed(2))
      this.setData({
        buttonTop: buttonTop, // 200/40
        startzhi:endzhi
      })
      wx.setStorageSync("endtop",buttonTop)
      wx.setStorageSync("startzhi",endzhi)
    }
  },

  buttonEnd: function (e) {

  },
  

  jiaozhun :async function(e){
    let value = wx.getStorageSync("jiaobuttontop")
    let startzhi = wx.getStorageSync("startzhi")
    if (value==''||startzhi==''){
      this.setData({
        isStart:false,
        buttonTop:540,
        jiaozhi:5.40,
        jiaole:false,
      })
    }else{
      this.setData({
        isStart:false,
        jiaole:false,
        buttonTop:value,
        jiaozhi:5.40,
      })
    }

  },

  tap() {
    this.setData({
      x: 30,
      y: 30
    })
  },

  jiaozhunclose(){
    wx.setStorageSync("jiaobuttontop",this.data.buttonTop)
    wx.setStorageSync("startzhi",this.data.jiaozhi)
    wx.setStorageSync("singlele",(this.data.buttonTop)/67.5)
    // console.log(this.data.buttonTop)
    this.setData({
      isStart:true,
      startzhi:this.data.jiaozhi,
      jiaole:true,
      single:(this.data.buttonTop)/67.5,
      jiaobuttontop:(this.data.buttonTop/2)/54
    })
    // console.log((this.data.buttonTop/2)/54,'比例')
  },

  bindvalue: function(e) {
    // // console.log(e.detail.value)
    this.setData({
      value: e.detail.value
    })
  },
  bindvalue2: function(e) {
    // // console.log(e)
    this.setData({
      value2: e.detail.value
    })
  },
  assignment() {
    this.setData({
      val: 50
    })
  },
  changeheight(e){
    // console.log(e)
  },
  onShareAppMessage() {
    return {
      title: "在线直尺",
      path: "/pages/calculationTools/pages/straight/index",
      imageUrl: '/images/function_icon/straightIcon.png',
    }
  },
  onShareTimeline() {
    return {
      title: '在线直尺',
      imageUrl: '/images/function_icon/straightIcon.png',
    }
  },
})